package com.hk.commons.vo.yingmi;

import com.hk.commons.utils.IPUtil;
import com.hk.commons.utils.TerminalTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created by Antinomy on 17/9/30.
 */
public class TerminalRequestDTO {
    private Logger logger = LoggerFactory.getLogger(TerminalRequestDTO.class);

    private String terminalIP;
    private String terminalType;
    private String terminalInfo;
    private String referenceNo;
    private String mobileId;


    public TerminalRequestDTO(HttpServletRequest request) {

        String phoneIP = request.getParameter("terminalIP");

        if (StringUtils.isNoneBlank(phoneIP)) {
            logger.info("terminalIP from mobile : "+phoneIP);
            this.terminalIP = phoneIP;
        } else {
            this.terminalIP = IPUtil.getIpAddr(request);
        }

        this.terminalInfo = IPUtil.getUserAgent(request);
        this.terminalType = TerminalTypeEnum.MOBILE_APP.getCode();
        this.referenceNo = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddhhmmssSSS"));
    }

    public String getTerminalIP() {
        return terminalIP;
    }

    public void setTerminalIP(String terminalIP) {
        this.terminalIP = terminalIP;
    }

    public String getTerminalType() {
        return terminalType;
    }

    public void setTerminalType(String terminalType) {
        this.terminalType = terminalType;
    }

    public String getTerminalInfo() {
        return terminalInfo;
    }

    public void setTerminalInfo(String terminalInfo) {
        this.terminalInfo = terminalInfo;
    }

    public String getReferenceNo() {
        return referenceNo;
    }

    public void setReferenceNo(String referenceNo) {
        this.referenceNo = referenceNo;
    }

    public String getMobileId() {
        return mobileId;
    }

    public void setMobileId(String mobileId) {
        this.mobileId = mobileId;
    }
}
